from login_ui import Ui_MainWindow as Login_Window_UI
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.Qt import *
from PyQt5.QtWidgets import QFileDialog, QMessageBox, QDockWidget, QListWidget
import sys
sys.path.append("swig_target/")
import maincpp

class Login_Window(QtWidgets.QWidget, Login_Window_UI):
    switch_window = QtCore.pyqtSignal()
    
    def __init__(self):
        super(Login_Window, self).__init__()
        self.window = QMainWindow()
        self.setupUi(self.window)
        self.pushButton.clicked.connect(self.verify)

    def verify(self):
        username = self.lineEdit_2.text()
        passwd = self.lineEdit.text()
        level = self.comboBox.currentIndex() # root(0) or normal(1)
        flag = self.comboBox_2.currentIndex() # central(0) or distributed(1)
        print("username = {}, passwd = {}".format(username, passwd))
        print("level = {}, flag = {}".format(level, flag))
        if maincpp.interface_login(username, passwd, level, flag):
            self.switch_window.emit()
        else:
            reply = QMessageBox.warning(self,"warning","incorrect username with passwd.")

    def show(self):
        self.window.show()

    def close(self):
        self.window.close()
